import Flutter
/**
 * 功能描述:mars 使用的task封装
 * 修改时间:
 * 修改描述:
 */
public class TaskWrapper {
    /**
     * 定义消息唯一标示
     */
    public var msgId:String = "";
    /**
     * mars使用的taskID
     * 获取待发送消息时,通过taskID获取
     */
    public var taskId:Int = 0;
    /**
     * mars使用的任务对象
     */
    public var task:CGITask? ;
    /**
     * 消息对象(待发送的消息)
     */
//    public var msgBean:IMsg?;
    
    
    public var msgDic:[String:Any];
    /**
     * 当前发送的命令是否需要server响应
     * 如果不需要,发送完成后直接返回success
     */
    public var isNeedServerResp = true;
    
    /**
    * 消息发送超时毫秒值
        */
    public var sendTimeoutMs:CLong = 0;
    
    /**
     * 结果回调到flutter使用的对象
     */
    public var result:FlutterResult?;
    /**
     * 任务超时毫秒值
     */
    public var timeOutMs = Const.SEND_MSG_TIMEOUT;

//    convenience init( task:CGITask,  msgBean:IMsg,sendTimeoutMs:CLong,  result:@escaping FlutterResult,  timeOutMs:Int) {
//        self.init(task: task, msgBean: msgBean, sendTimeoutMs: sendTimeoutMs, result: result, timeOutMs: sendTimeoutMs);
//        self.timeOutMs = timeOutMs;
//    }
    
    convenience init(task:CGITask,msgDic:[String : Any],sendTimeoutMs:CLong,result:@escaping FlutterResult,timeOutMs:Int) {
//        self.init(task: task, msgDic: msgDic as! [String : Any], isNeedServerResp: isNeedServerResp, sendTimeoutMs: timeOutMs, result: result);
        
        self.init(task: task, msgDic: msgDic as! [String : Any], sendTimeoutMs: timeOutMs, result: result, timeOutMs: timeOutMs);
        
        self.timeOutMs = timeOutMs;
    }
    
    
//cmdId:Int
    init(task:CGITask, msgDic:[String:Any],isNeedServerResp:Bool,sendTimeoutMs:CLong, result:@escaping FlutterResult) {
        self.result = result;
        self.task = task;
        self.taskId = Int(task.taskid);
//        self.msgBean = msgBean;
        self.msgDic = msgDic;
        if(msgDic.keys.contains("content")){
            let contenMsp = msgDic["content"] as! [String:Any];
//            self.msgDic = contenMsp;
            if(contenMsp.keys.contains("msgId")){
                self.msgId = contenMsp["msgId"] as! String;
            }
            
        }
        
        self.isNeedServerResp = isNeedServerResp;
        self.sendTimeoutMs = sendTimeoutMs;
      
        
    }

}
